﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class admin_module_Topic : System.Web.UI.UserControl
{
    Topic_BU tp_BU = new Topic_BU();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            getTopic();
        }
    }

    public void getTopic()
    {
        DataTable dt = tp_BU.getALLTopic();
        DataTable list_topic = new DataTable();
        list_topic.Columns.Add("id");
        list_topic.Columns.Add("name");
        list_topic.Columns.Add("href");
        DataRow dr;
        foreach (DataRow r in dt.Rows)
        {
            dr = list_topic.NewRow();
            dr["id"] = r["topic_id"];
            dr["name"] = r["topic_name"];
            dr["href"] = "~//admin//default.aspx?action=form_topic&path=" + Convert.ToInt32(r["topic_id"]);
            list_topic.Rows.Add(dr);
        }

        dlTopic.DataSource = list_topic;
        dlTopic.DataBind();
        if (list_topic.Rows.Count == 0)
        {
            text_empty.Visible = true;
        }
    }
    protected void dlTopic_DeleteCommand(object source, DataListCommandEventArgs e)
    {
        int id = Convert.ToInt32(dlTopic.DataKeys[e.Item.ItemIndex]);
        int result=tp_BU.deleteTopic(id);
        getTopic();       
    }
}